package com.tanhua.management.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.tanhua.management.service.MessagesService;
import com.tanhua.management.vo.MessageVo;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("manage")
public class MessagesController {


    @Autowired
    private MessagesService messagesService;

    @PostMapping("messages/pass")
    public ResponseEntity<MessageVo> passPublish(@RequestBody String[] StrIds){
        try {
            String  result =  messagesService.passPublish(StrIds);
            MessageVo messageVo =new MessageVo(result);
            if(StrUtil.isNotEmpty(result)){
                return ResponseEntity.ok(messageVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping("messages/reject")
    public ResponseEntity<MessageVo> rejectPublish(@RequestBody String[] StrIds){
        try {
            String  result =  messagesService.rejectPublish(StrIds);
            MessageVo messageVo =new MessageVo(result);
            if(StrUtil.isNotEmpty(result)){
                return ResponseEntity.ok(messageVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping("messages/{id}/top")
    public ResponseEntity<MessageVo> topPublish(@PathVariable("id")String StrId){
        try {
            String  result =  messagesService.topPublish(StrId);
            MessageVo messageVo =new MessageVo(result);
            if(StrUtil.isNotEmpty(result)){
                return ResponseEntity.ok(messageVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping("messages/{id}/untop")
    public ResponseEntity<MessageVo> untopPublish(@PathVariable("id")String StrId){
        try {
            String  result =  messagesService.untopPublish(StrId);
            MessageVo messageVo =new MessageVo(result);
            if(StrUtil.isNotEmpty(result)){
                return ResponseEntity.ok(messageVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping("messages/revocation")
    public ResponseEntity<MessageVo> revocationPublish(@RequestBody String[] StrIds){
        try {

            String  result =  messagesService.revocationPublish(StrIds);
            MessageVo messageVo =new MessageVo(result);
            if(StrUtil.isNotEmpty(result)){
                return ResponseEntity.ok(messageVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
